<link rel="stylesheet" href="<%- Virtual_Path.Static %>main/css/profile.css"/>
<div class="main-container">
    <div class="xiu-dialog" id="bd-password">
        <div class="divColorbox_Header" class="xiu-dialog-head">
            <span><i class="fa fa-star"></i><span>我要兑换（1金豆=1金币）</span></span>
            <a class="Refresh"></a><a class="Close"></a>
        </div>
        <p class="valid-tip"></p>
        <div class="xiu-dialog-body">
            <div class="form-group">
                <label for="" class="form-label">
                    需消耗的金豆：
                </label>
                <div class="form-hozinput">
                    <!--<input type="text" name="" class="form-control" placeholder="请输入需兑换的金豆" id=""/>-->
                    <select name="exchange_Beans" id="J_Exchange_Beans" style="margin-top: 7px;line-height: 17px; border: 1px solid #cdcdcd; color: #999;">
                        <option value="100" selected>100</option>
                        <option value="200">200</option>
                        <option value="500">500</option>
                        <option value="1000">1000</option>
                        <option value="5000">5000</option>
                        <option value="10000">10000</option>
                        <option value="50000">50000</option>
                        <option value="100000">100000</option>
                        <option value="200000">200000</option>
                        <option value="500000">500000</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label for="" class="form-label">
                    可获得的金币：
                </label>
                <div class="form-hozinput">
                    <p id="J_Exchange_Coin"  style="color: #ff9f2e; line-height: 17px;margin-top: 7px;">100</p>
                </div>
            </div>
            <div class="form-group">
                <div class="form-hozinput form-hozinput-ml">
                    <input type="button" name="" class="form-button" value="提交" id="J_Exchange_sub"/>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    $(function () {
        if (!_StateData.IsLogin) {
            $.CommonMain.Modal_Tip('请先登录', {Timeout: 1000});
            location.href = '/';
        }
        $("#bd-password").show();

        //计算兑换的金币
        $('#J_Exchange_Beans').on("change",function(){
            var UserBeans = $.trim($(this).val());//获取 金额
            if(parseInt(UserBeans)>_PageData.Beans){
                $.CommonMain.Modal_Tip('您的金豆不足，赶快去充值吧~', {Timeout: 1000});
                $("#J_Exchange_Coin").text('');
                return;
            }else{
                $("#J_Exchange_Coin").text(UserBeans);
            }
        });
        $('#J_Exchange_sub').on('click', function () {
            var params = {};
            params.Beans = $.trim($('[name="exchange_Beans"]').val());
            if(params.Beans>_PageData.Beans){
                $.CommonMain.Modal_Tip('您的金豆不足，赶快去充值吧~', {Timeout: 2000});
                $('[name="exchange_Beans"]').focus();
                return false;
            }
            $.KOC.Loading.Open();
            $.ajax({
                url: '/ajax/user.user-info.currencyexchange',
                type: 'post',
                dataType: 'json',
                data: {
                    Beans: params.Beans
                },
                success: function (data) {
                    $.KOC.Loading.Close();
                    if (data.flag !== 0) {
                        $.KOC.Tips.Open("Error", data.msg + "(" + data.flag + ")", {Timeout: 2000});
                        return;
                    }
                    $.CommonMain.Modal_Tip('兑换成功', {
                        Timeout: 3000,
                        onClose: function () {
                            $.Common.ModalWindow.fnEnter();
                        }
                    });
                }
            });
        });
    })
</script>